package summer.sample.persons;

import cn.hn.java.summer.db.BaseDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import summer.sample.persons.db.Actor;
import summer.sample.persons.model.ActorVo;

import java.util.List;

/**
 * Created by xw2sy on 2017-04-20.
 */
@Controller()
@RequestMapping("/persons")
public class PersonsController {
    @Autowired
    BaseDao baseDao;

    @RequestMapping("/actors")
    public List<Actor> getActors(){
        return baseDao.list(Actor.class);
    }

    @RequestMapping("/actors2")
    public List<Actor> getActors2(ActorVo actorVo){
        return baseDao.list(
                "getActors+condition"+(actorVo.getFirstName()!=null?1:2),
                Actor.class,
                actorVo
        );
    }

    @RequestMapping("/actors3")
    public List<Actor> getActors3(ActorVo actorVo){
        return baseDao.list(
                "getActors",
                Actor.class,
                actorVo
        );
    }

    @RequestMapping("/actors4")
    public List<Actor> getActors4(ActorVo actorVo){
        return baseDao.list(
                "getActors+condition3",
                Actor.class,
                baseDao.ce().set("actorIds",new int[]{1,2,3})
        );
    }
}
